<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="spring" uri="/WEB-INF/tlds/spring.tld"%>
<%@ taglib prefix="c" uri="/WEB-INF/tlds/c.tld"%>
<c:set var="BasePath" value="${pageContext.request.contextPath}"></c:set>
<c:set var="Plugins" value="${pageContext.request.contextPath}/res/plugins"></c:set>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>新增次品退货</title>
<link href="${Plugins}/ligerUI/skins/Aqua/css/ligerui-all.css" rel="stylesheet" type="text/css" />
<link href="${Plugins}/ligerUI/skins/ligerui-icons.css" rel="stylesheet" type="text/css" />
<script src="${Plugins}/jquery/jquery-1.3.2.min.js"	type="text/javascript"></script>
<script src="${Plugins}/ligerUI/js/ligerui.min.js" type="text/javascript"></script>
<script src="${Plugins}/jquery-validation/jquery.validate.min.js" type="text/javascript"></script>
<script src="${Plugins}/jquery-validation/jquery.metadata.js" type="text/javascript"></script>
<script src="${Plugins}/jquery-validation/messages_cn.js" type="text/javascript"></script>
<script src="${BasePath}/res/js/common/jquery.form.js" type="text/javascript"></script>
<script src="${BasePath}/res/js/common/jquery.validate.method.js" type="text/javascript"></script>
<script type="text/javascript" src="${BasePath}/res/js/ligerCommon.js"></script>
<script src="${Plugins}/datepicker/WdatePicker.js" type="text/javascript"></script>
<script type="text/javascript" src="${BasePath}/res/js/json2.js"></script>

<style type="text/css">
    body{ font-size:12px;}
    .l-table-edit {}
    .l-table-edit-td{ padding:4px;}
    .l-button-submit,.l-button-test{width:80px; float:left; margin-left:10px; padding-bottom:2px;}
    .l-verify-tip{ left:230px; top:120px;}
    .navbar {
		height: 20px;
		border-bottom: #E6E6E6 solid 1px;
		line-height: 20px;
	}
	.p-tab .s-lab{font-size:12px;font-family:"微软雅黑",​"宋体",​Arial,​sans-serif;}
	input.l-textarea{width:170px;height:20px;font-size:12px;}
</style>
</head>
<body style="padding:10px">
<div class="navbar">
		<span>您当前的位置：</span>
		次品退货管理 &gt; 新增次品退货  
</div>
<form name="form1" method="post" action="add_defectReplce.do" id="form1" onsubmit="return setGridData()">
<!-- <input type="text" id="gridData" name="defectives" value=""  />  -->
   <table  cellpadding="0" cellspacing="0" class="l-table-edit p-tab"" >
    <!-- <tr>
        <td align="right" class="l-table-edit-td s-lab"><font  color="red">*</font>退货单号：</td>
        <td align="left" width="100%" class="l-table-edit-td "><input name="DefectReplceId" type="text" id="DefectReplceId"  class="l-textarea" maxlength="50" validate="{required:true,rangelength:[1,50]}" /></td>
        <td align="left"></td>
    </tr> -->
    
    <tr>
        <td align="right" class="l-table-edit-td s-lab"><font  color="red">*</font>退货名称：</td>
        <td align="left" width="100%" class="l-table-edit-td "><input name="DefectReplceName" type="text" id="DefectReplceName"  class="l-textarea" maxlength="50" validate="{required:true,rangelength:[1,50]}" value="${defectReplceVo.DefectReplceName}"/></td>
        <td align="left"></td>
    </tr>
    <br/>
   
     <tr style="display: none;">
        <td align="right" class="l-table-edit-td s-lab" >业务类型：</td>
        <td align="left" class="l-table-edit-td "> 
    		<select style=" z-index: -999;font-size: 12px;" id="replceType" name="replceType" value="${defectReplceVo.replceType}" class="l-textarea">
    		    <option value="">请选择</option>
				<option value="1" selected="selected">退货</option>
				<option value="2">换货</option>
			</select>
		</td>
		<td align="left"></td>
    </tr> 
    
     <tr>
        <td align="right" class="l-table-edit-td s-lab" >选择仓库：</td>
        <td align="left" class="l-table-edit-td "> 
    		 <select style="z-index: -999;font-size: 12px;" id="warehouseNo"  name="warehouseNo" value="${defectReplceVo.whNo}" style="width: 130px">
            <option value="">请选择</option>
            <c:forEach var="temp" items="${whareHouse}">
            	<option value="${temp.whNo}">${temp.whName}</option>
            </c:forEach>
        </select>
		</td>
		<td align="left"></td>
    </tr> 
    
     <tr>
      <td align="right" class="l-table-edit-td s-lab"><font  color="red">*</font>供应商名称：</td>
          <td align="left" width="100%" class="l-table-edit-td s-lab">
           <input name="supName" id="supName" value="${prv.supName }" class="l-textarea" maxlength="50" validate="{required:true,rangelength:[1,50]}" />
           <input name="supCode" type="hidden" id="supId" value="${prv.supCode }">
           <input type="button" value="选择供应商" id="elect_purSupper" class="l-button l-button-test" />
          </td>
       <td align="left"></td>
    </tr> 
    
    
     <tr>
        <td align="right" class="l-table-edit-td s-lab">
        	<input type="button" value="选择次品" id="elect_product" class="l-button l-button-test" />
        </td>
        <td align="left" class="l-table-edit-td ">
        	<input type="hidden" id="productlist" name="productlist" />
        	<!-- <input type="button" onclick="valData();" value="ssss"  /> -->
        </td>
        <td align="left"></td>
     </tr>
      <tr id="xzProductList" style="display: none;">
     <tr>
        <td colspan="3" align="left" class="l-table-edit-td s-lab">
        <div id="maingrid" style="margin:0; padding:0"></div>
		  <div style="display:none;">
		  <!-- 展示列表数据  -->
		</div>
		</td>
     </tr>

</table>


<input type="submit" value="确定" id="submit1" class="l-button l-button-submit" /> 
<input type="button" value="取消" name="tests" id="tests" class="l-button l-button-test" />
</form>
</body>
<script>

//供应商编码
var scode ="";
//供应商名称
var sname="";
//成本价格
var actprice="";

var basePath ="${BasePath}";

$(document).ready(function(){

	//选择商品子窗口
	$("#elect_product").click(function(){
		list = new Array();
	   	var m =$.ligerDialog.open({
	   				title:'新增次品退货列表',
	   				url:'${BasePath}/product/defectiveReplacement/getCommodityList.do?supCode='+scode,
	   				height:500,width:700,
	   				buttons: [{ text: '确定', onclick: function (item, dialog) { 
	   									dialog.frame.valProd();
	   									if(!dialog.frame.isOut) return false;
	   									addProduct(); 
	   									dialog.close(); 
	   								} 
	   						  },
	   				          { text: '取消', onclick: function (item, dialog) { dialog.close(); list = new Array();} } ],
	   				isResize: false, 
	   				isDrag: false 
	   		});
	   	m.show(); 
	});
	
	addProduct();
	
	//选择供应商
	//选择商品子窗口
	$("#elect_purSupper").click(function(){
		//getSupplyInfo();
		list = new Array();
	   	var m =$.ligerDialog.open({
	   				title:'新增次品退货供应商列表',
	   				url:'${BasePath}/product/defectiveReplacement/getSupplierInfoList.do',
	   				height:500,width:700,
	   				buttons: [{ text: '确定', onclick: function (item, dialog) { 
	   					
	   									/* alert(JSON.stringify($("#elect_purSupper").getData())); */
	   									//$('#supName').val('2132');
	   									//addProduct(); 
	   									$("#supName").val(sname);
  		            					$("#supId").val(scode);
	   									dialog.close(); 
	   								} 
	   						  },
	   				          { text: '取消', onclick: function (item, dialog) { dialog.close(); list = new Array();} } ],
	   				isResize: false, 
	   				isDrag: false 
	   		});
	   	m.show();
	});
	
	
});


//查询
var sel = "";
//临时请购商品集合
var list = new Array();
//请购商品集合
var commoditylist = new Array();
var g = "";
//请购商品列表
function addProduct(){
	commoditylist = commoditylist.concat(list);
	//$.ligerDialog.warn(JSON.stringify(commoditylist));
	commodityData = {"Rows": commoditylist, "Total": commoditylist.length};
	grid = $("#maingrid").ligerGrid({
        columns: [
        /* { display: '商品编号', name: 'productId' ,render:function(rowdata,rowindex,value){
        	 rowdata.productId = rowdata.prodNo; 
           return rowdata.prodNo; 
        }},
        { display: '商品名称', name: 'productName' ,render:function(rowdata,rowindex,value){
       	 rowdata.prodBarCode = rowdata.commoNo; 
          return rowdata.commoNo; 
       }},
      { display: '退货数量', name: 'defectiveNumber' ,render:function(rowdata,rowindex,value){
       	 rowdata.warehouse = rowdata.prodNo; 
          return rowdata.commoName; 
       }},
       { display: '问题描述', name: 'description' ,render:function(rowdata,rowindex,value){
         	 rowdata.warehouse = rowdata.prodNo; 
            return rowdata.commoName; 
         }}, */
        
       /*  { display: '采购单号', name: 'purchaseNo',editor:{type:'string'}},
        { display: '次品原因', name: 'defectiveReason',editor:{type:'string'}},
        { display: '次品处理方式', name: 'dealWith',editor:{type:'string'}}, */
        { display: '货品编号', name: 'prodNo'},
        { display: '商品编号', name: 'commoNo'},
        { display: '商品名称', name: 'commoName'},
        { display: '规格', name: 'specName'},
        { display: '仓库名称', name: 'whName'},
        { display: '供应商名称', name: 'supName'},
        { display: '退货数量', name: 'defectiveNumber'},
        /* { display: '次品原因', name: 'description' }, */
        { display: '次品原因', name: 'defectiveReason' },
        { display: '操作', isSort: false, render: function (rowdata, rowindex, value){
           	var  text = "<input type='button' value='删除' onclick='removeThis("+rowindex+");' />";
            return text;
        	}
        }
        ], 
        width: '100%',
        height: '330',
        usePager: false,enabledEdit: true,
        data: $.extend(true,{},commodityData)
    });
	list = new Array();
	//
	  g= $("#maingrid").ligerGrid({
		         grid: grid,
	 			pageSize:30,
	            width: '100%',
	            height: '92%',
	            dataType: 'server', 
	            dataAction: 'server',
	            pagesizeParmName: 'pageSize',
	            enabledEdit: true
	        });
	        
	//
}
	 function setGridData(){
	 		var data = g.getData();
	 		var dataStr = JSON.stringify (data);
	 		$('#gridData').val(dataStr);
	 		return true;
	}


//删除商品
function removeThis(o) {
	commoditylist.splice(o,1);
	addProduct();
}

function valData() {
	
	$("#productlist").val(JSON.stringify(commoditylist));
	
}

//from提交
$(function ()
		{
			//validate
		    $.metadata.setType("attr", "validate");
		    var v = $("form").validate({
		        errorPlacement: function (lable, element)
		        {
		        	lable.ligerHideTip();
		            if (element.hasClass("l-textarea"))
		            {
		                element.ligerTip({ content: lable.html(), target: element[0] }); 
		            }
		            else if (element.hasClass("l-text-field"))
		            {
		                element.parent().ligerTip({ content: lable.html(), target: element[0] });
		            }
		            else
		            {
		                lable.appendTo(element.parents("td:first").next("td"));
		            }
		            
		        },
		        submitHandler:function()
		        {
		        	$("form .l-text,.l-textarea").ligerHideTip();
		        	valData();
		        	/* if(!prod) return prod; */
		            var options = {
		            		type: 'POST',
		            		beforeSend: function(){
		            			$("#form1").find(":submit,:button").attr("disabled", true);
		            		},
		            		success: function(data){
		            			if(data=="success") {
		            				window.parent.f_tip('新增成功');
		            				close_liger_tab();
		            			} else {
		            				window.parent.f_tip('新增失败');
		            			}
		            		}
		            	}, $form1 = $("#form1");
		           $form1.ajaxSubmit(options);
		           return false;
		        }
		    });
}); 
// 取消
$("#tests").click(function() {
	close_liger_tab();
});	



//供应商编码
var scode ="";
//供应商名称
var sname="";
//成本价格
var actprice="";

//选择供应商
function getSupplyInfo(prodNo,index){
	scode = sname= actprice="";
	//var cid=grid.getData()[index].prodNo;
	  m=$.ligerDialog.open({title:'选择供应商',
		 url:"${BasePath}/manager/purchase/orders/pageFinderSupplier.do?prodNo='"+prodNo+"'",height:400,width:800,isResize: false,
		 isDrag: false,
		 buttons: [ 
		            { text: '确定', onclick: function (item, dialog) {
		            		getActprice(prodNo);
		            		commoditylist[index].actprice = actprice;
		            		commoditylist[index].purSuppNo = scode;
		            		commoditylist[index].purSuppName = sname;
		            		dialog.close();
		            		addProduct();
		            	} 
		            }, 
		            { text: '取消', onclick: function (item, dialog) { dialog.close(); } }] 
		 });
	
	 m.show(); 
}
</script>
</html>